const logKey = `/log/user/account`;
import AsyncStorage from '@react-native-community/async-storage';

interface Res {
    username?: string,
    password?: string
}

export const get = async (): Promise<Res> => {
    const res = (
        await AsyncStorage.
        getItem(logKey) || `{}`
    )
    return JSON.parse(res);
}

export const set = async (input: Res) => {
    await AsyncStorage.setItem(
        logKey, JSON.stringify(input)
    )
}


export const clear = async () => {
    await AsyncStorage.removeItem(logKey);
}

export const update = async (data:Res) => {
    const res = await get();
    await set({ ...res, ...data })
}
